#!/bin/bash
chrootEnvPath=/opt/new-system-env
#if [[ `whoami` != "root" ]]; then
#    echo 请使用 root 权限运行
#    exit 1
#fi
if [[ ! -f ~/.config/gx-env/chroot ]]; then
    #if [[ `whoami` != root ]]; then
    #    if [[ ! -d $chrootEnvPath/home/$USER ]]; then
    #        pkexec env `gx-env-show-env-list` gx-env-init
    #    fi
    #fi
    pkexec env `gx-env-show-env-list` bwrap  --dev-bind / / --dev-bind $chrootEnvPath/etc /etc --dev-bind $chrootEnvPath/opt /opt --dev-bind $chrootEnvPath/usr /usr --dev-bind $chrootEnvPath/var /var --dev-bind $chrootEnvPath/gx-env /gx-env --dev-bind /etc/resolv.conf /etc/resolv.conf "$@"
    #pkexec gx-env-load-desktop
    exit
fi
echo aa > /tmp/env-$USER.txt
if [[ ! -f $chrootEnvPath/tmp/env-$USER.txt ]]; then
    echo 未挂载目录，立即挂载
    pkexec env `gx-env-show-env-list` gx-env-mount-root
fi
command="$@"
#echo $command
pkexec env `gx-env-show-env-list` chroot $chrootEnvPath "$@"
#pkexec gx-env-load-desktop
#echo $@